package com.ftl;


//import freemarker.template.Configuration;

import freemarker.template.Configuration;
import freemarker.template.Template;

import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class mobile_setmeal_detal {
    public static void main(String[] args)throws Exception {
//1.创建配置类
        //1.创建配置类
        Configuration configuration=new Configuration(Configuration.getVersion());
        //2.设置模板所在的目录
        configuration.setDirectoryForTemplateLoading(new File("D:\\develop\\IdeaProjects\\my_healthy\\health_parent\\health_service_provider\\src\\main\\webapp\\WEB-INF\\ftl\\"));
//3.设置字符集
        configuration.setDefaultEncoding("utf-8");
//4.加载模板
        Template template = configuration.getTemplate("mobile_setmeal_detail.ftl");
//5.创建数据模型
        Map map=new HashMap();

        List<Map<String,String>> setmealList = new ArrayList<>();
//        测试数据
            Map<String,String> map1 = new HashMap<>();
            map1.put("name","张三");
            map1.put("age","10");
            map1.put("id","1");
            map1.put("sex","1");
            map1.put("img","1");
            map1.put("remark","我是张三");
            setmealList.add(map1);

        Map<String,String> map2 = new HashMap<>();
        map2.put("name","李四");
        map2.put("id","1");
        map2.put("age","22");
        map2.put("sex","0");
        map2.put("img","1");
        map2.put("remark","我是李四");
        setmealList.add(map2);

        Map<String,String> map3 = new HashMap<>();
        map3.put("name","李四");
        map3.put("id","1");
        map3.put("age","22");
        map3.put("sex","2");
        map3.put("img","1");
        map3.put("remark","我是李四");
        setmealList.add(map3);

        map.put("setmealList",setmealList);
//6.创建Writer对象
        Writer out =new FileWriter(new File("d:\\test.html"));
//7.输出
        template.process(map, out);
//8.关闭Writer对象
        out.close();
    }
}
